<template>
    <div id="dialogAdvertisingPicture">
        <el-dialog v-if="dialogFormVisible" :visible.sync="dialogFormVisible" :title="dialogTitle" width="620px" :close-on-click-modal="false">
            <el-form
            ref="subForm"
            :inline="true"
            :model="submitFormData"
            :rules="newFloorRules"
            class="search-form-inline"
            label-width="110px"
            size="small"
            :label-position="labelPosition"
            >
            <el-form-item label="广告标题" prop="title">
                <el-input v-model="submitFormData.title" />
            </el-form-item>
            <el-row>
             <el-form-item label="PC图片类型" prop="pcType">
                <el-input v-model="submitFormData.pcType" />
            </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="广告类型" prop="type">
                    <el-select v-model="submitFormData.type">
                        <el-option v-for="item in enums.adType" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="广告时间">
                    <el-date-picker v-model="submitFormData.timeScope" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="广告图片">
                    <elUpload
                    ref="upload"
                    :autoUpload="false"
                    :fileList="fileList" 
                    :dragable="false"
                    ></elUpload>
                </el-form-item>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
    </el-dialog>
</div>
</template>
<script>
import elUpload from "@/components/xForm/elUpload";
import apisAd from "@/api/shopDecoration/ad"; //广告图片接口
export default {
    name: "dialogAdvertisingPicture",
    components: { elUpload, apisAd },
    data() {
        return {
            dialogFormVisible: false,
            dialogTitle: "",
            labelPosition: "right",
            submitFormData: {
                id:'',
                title: "",
                type: "",
                activity: "",
                timeScope: [],
                provinceCity: [],
                enable: 1,
                link: "",
                imgUrl:'',
                pcType:''
            },
            // 上传图片
            fileList: []
        };
    },
    methods: {
        open(data) {
            if(data && data.id){
                this.dialogTitle = "修改广告图";
                apisAd.getDetail(data.id).then(d=>{
                    this.submitFormData = d.data.ad;
                })
            } else {
                this.dialogTitle = "新增广告图";
                this.submitFormData = {};
            }
            this.dialogFormVisible = true;
        },
        submitForm() {
            apisAd.submitForm(this.submitFormData).then(d => {
                this.dialogFormVisible = false;
                this.$parent.getList();  
            })
        }
    }
};
</script>
